#!/bin/bash
set -xe

go build -o distribkv src/main.go 
cp src/sharding.toml sharding.toml
rm -rf ~/go/bin/distribkv
mv distribkv ~/go/bin/distribkv

trap 'killall distribkv; rm -rf *.db' SIGINT

cd $(dirname $0)

killall distribkv || true

sleep 0.1


# $HOME/go/bin/distribkv -db-location=moscow.db --http-addr=127.0.0.1:9999 -config-file=sharding.toml -shard=Moscow &
# $HOME/go/bin/distribkv -db-location=minsk.db --http-addr=127.0.0.1:9998 -config-file=sharding.toml -shard=Minsk &
# $HOME/go/bin/distribkv -db-location=kiev.db --http-addr=127.0.0.1:9997 -config-file=sharding.toml -shard=Kiev &

$HOME/go/bin/distribkv -db-location=moscow.db  -config-file=sharding.toml -shard=Moscow &
$HOME/go/bin/distribkv -db-location=minsk.db   -config-file=sharding.toml -shard=Minsk &
$HOME/go/bin/distribkv -db-location=kiev.db    -config-file=sharding.toml -shard=Kiev &

rm -rf *.db

wait